home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-11 | 7.4 KB | 272 lines | [TEXT/MMCC] |
- /************************************************************************************
-
- File: MoMathComponent.c
-
- Contains: Extended math component routines.
-
- Written by: Gary Woodcock
-
- Copyright: © 1992 by Apple Computer, Inc.
-
- Change History (most recent first):
-
-
- Project settings for 68K
- Code model: Small, Smart or Large
- Link Single Segment: on (VERY important)
- Project type: Code Resource
- File name: MoMath_Component
- Sym name: MoMath_Component.SYM (not generated)
- Resource name: Extended Math Component
- Header type: Standard
- Multi Segment: on or off
- ResType: _68K
- ID: 130
- SegType blank (unused since we are linking single segment)
- Creator: gwck
- File type: thng
- Resource flags: SysHeap
- Project setup:
- Segment 1 (Main Segment): MoMathComponent.c
- Segment 2 (Group2): MacOS.lib, FatMoMathComponent.rsrc (See warning below)
- Segment 3 (Group3): and MathComponentCommon.c
-
- Project settings for PPC
- Project type: Code Resource
- File name: MoMath_Component
- Sym name: MoMath_Component.SYM (not generated)
- Resource name: Extended Math Component
- Header type: None (VERY important)
- ResType: _PPc
- ID: 130
- Creator: gwck
- File type: thng
- Resource flags: SysHeap
- Merge To File on
- Expand Uninitialized Data: on
- Main Entry Point MainRD (VERY important)
- Project setup:
- Group 1 (Main Group): MoMathComponent.c
- Group 2 (Group2): InterfaceLib, MathLib, ToolsLib.o
- Group 3 (Group3): MathComponentCommon.c
-
- ***Warning*** FatMoMathComponent.rsrc has an extended thng resource which
- is set to require both PPC and 68K code. If you want to test the 68K
- component by itself, use MoMathComponent.rsrc, instead.
-
- CW components need to have the Link Single Segment switch checked. The Multi-
- segment switch can be checked or unchecked as fits your needs. (Please
- see the User Guide for which situations require the Multi-segment switch.)
- Putting everything into one segment eliminates segment loader errors that
- would occur if the startup code tried to call GetResource before
- OpenComponentResFile is called. Components written in C are moveable, components
- written in C++ with virtual functions probably aren't. Please see the
- C++ XCMD example on the CD for an example of how to deal C++ code resources.
-
- Project settings, port to PPC and comments by
- Mark Anderson
- metrowerks
- 12/1/94
-
- ************************************************************************************/
-
- //-----------------------------------------------------------------------
- // Includes
-
- #include "MathComponent.h"
- #include "MathComponentPrivate.h"
- #include "MathComponentCommon.h"
- #include "MoMathComponent.h"
- #include "MoMathComponentPrivate.h"
- #include <Errors.h>
- #ifndef powerc
- #include <A4Stuff.h>
- #endif
-
- //-----------------------------------------------------------------------
- // Prototype (can't be in header or there is a conflict with Component Tester)
- #ifndef DEBUG_IT
- pascal ComponentResult main (ComponentParameters *params,
- Handle storage);
- #endif
-
- //-----------------------------------------------------------------------
- // PPC Globals
- #ifdef powerc
-
- INSTANTIATE_ROUTINE_DESCRIPTOR(MoMathDoAdd);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MoMathCanDo);
-
- #ifndef DEBUG_IT // This file must occur after MathComponent.c in the project window
- // otherwise these globals get defined twice
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathOpen);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathClose);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathVersion);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathTarget);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathDoDivide);
- INSTANTIATE_ROUTINE_DESCRIPTOR(MathDoMultiply);
-
- RoutineDescriptor MainRD = BUILD_ROUTINE_DESCRIPTOR(uppComponentRoutineProcInfo, main);
- ProcInfoType __procinfo = uppComponentRoutineProcInfo;
- #else
- extern RoutineDescriptor MathOpenRD;
- extern RoutineDescriptor MathCloseRD;
- extern RoutineDescriptor MathVersionRD;
- extern RoutineDescriptor MathTargetRD;
- extern RoutineDescriptor MathDoDivideRD;
- extern RoutineDescriptor MathDoMultiplyRD;
- #endif
- #endif
-
- //-----------------------------------------------------------------------
- #ifdef DEBUG_IT
-
- // Use this declaration when we're running linked (for debugging)
- pascal ComponentResult MoMathDispatcher (ComponentParameters *params,
- Handle storage)
-
- #else
-
- // Use this declaration when we're a standalone component
- pascal ComponentResult main (ComponentParameters *params,
- Handle storage)
-
- #endif DEBUG_IT
-
- {
- // This routine is the main dispatcher for the MoMath component
-
- ComponentResult result = noErr;
-
- #if !defined(powerc) && !defined(DEBUG_IT)
- long oldA4;
-
- oldA4 = SetCurrentA4();
- #endif
-
-
- // Did we get a Component Manager request code (< 0)?
- if (params->what < 0)
- {
- switch (params->what)
- {
- case kComponentOpenSelect: // Open request
- {
- result = CallComponentFunctionUniv(params, MathOpen);
- break;
- }
-
- case kComponentCloseSelect: // Close request
- {
- //if open fails, close gets called so
- //globals aren't allocated
- if (!storage)
- return result;
- result = CallComponentFunctionWithStorageUniv(storage, params, MathClose);
- break;
- }
- case kComponentCanDoSelect: // Can Do request
- {
- result = CallComponentFunctionUniv(params, MoMathCanDo);
- break;
- }
- case kComponentVersionSelect: // Version request
- {
- result = CallComponentFunctionUniv(params, MathVersion);
- break;
- }
- case kComponentTargetSelect: // Target request
- {
- result = CallComponentFunctionWithStorageUniv(storage, params, MathTarget);
- break;
- }
- case kComponentRegisterSelect: // Register request not supported
- default: // Unknown request
- {
- result = paramErr;
- break;
- }
- }
-
-
- }
- else // Was it one of our request codes?
- {
- switch (params->what)
- {
- // math component selectors
- case kDoDivideSelect: // Divide request
- {
- result = CallComponentFunctionUniv(params, MathDoDivide);
- break;
- }
- case kDoMultiplySelect: // Multiply request
- {
- result = CallComponentFunctionUniv(params, MathDoMultiply);
- break;
- }
- case kDoAddSelect: // Add request
- {
- result = CallComponentFunctionUniv(params, MoMathDoAdd);
- break;
- }
- default: // Unknown request
- {
- result = paramErr;
- break;
- }
-
- }
- }
-
-
- #if !defined(powerc) && !defined(DEBUG_IT)
- SetA4(oldA4);
- #endif
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MoMathCanDo (short selector)
- {
- switch (selector)
- {
- // Component Manager request codes
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- case kComponentTargetSelect:
-
- // Math component request codes
- case kDoDivideSelect:
- case kDoMultiplySelect:
-
- // MoMath component request codes
- case kDoAddSelect:
- {
- return (true);
- }
- case kComponentRegisterSelect: // Register request not supported
- default: // Not a request code we recognize
- {
- return (false);
- }
- }
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MoMathDoAdd (short firstNum,
- short secondNum,
- short *additionResult)
- {
- ComponentResult result = noErr;
-
- *additionResult = firstNum + secondNum;
-
- return (result);
- }
-
-